package com.jwthhealth_pub.old.sportfitness.presenter;

import android.os.Bundle;
import android.os.Message;
import android.util.Log;

import com.jwthhealth_pub.old.api.ApiHelper;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.sportfitness.module.SprotCourseInfoModule;
import com.jwthhealth_pub.old.sportfitness.view.SportCourseInfoActivity;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/1/5.
 */

public class ISportCourseInfoPresenterCompl implements ISportCourseInfoPresenter {

    private SportCourseInfoActivity activity;

    public ISportCourseInfoPresenterCompl(SportCourseInfoActivity activity) {
        this.activity = activity;
    }

    @Override
    public void getData(String id) {
        activity.setRequest(true);
        Call<SprotCourseInfoModule> sprotCourseInfoModuleCall = ApiHelper.sportCourseInfoRequest(id);
        sprotCourseInfoModuleCall.enqueue(new Callback<SprotCourseInfoModule>() {
            @Override
            public void onResponse(Call<SprotCourseInfoModule> call, Response<SprotCourseInfoModule> response) {
                SprotCourseInfoModule body = response.body();
                if (body.getCode().equals("0")){
                    Message message = new Message();
                    Bundle bundle = new Bundle();
                    bundle.putSerializable(Constant.SPORT_DATA, body);
                    message.setData(bundle);
                    activity.mHandler.sendMessage(message);
                }else {
                    Log.d("ISportCourseInfoPresent", "fail");
                }
            }

            @Override
            public void onFailure(Call<SprotCourseInfoModule> call, Throwable t) {
                Log.d("ISportCourseInfoPresent", "fail");
            }
        });
    }
}
